﻿using System;
using System.Web.Routing;
using Microsoft.AspNet.SignalR;

namespace Web.Server.App_Start
{
    public static class SignalRConfig
    {
        public static void Register()
        {
            //Use Redis store for SignalR
            //GlobalHost.DependencyResolver.UseRedis("server", port, "password", "AppName");
            // Make long polling connections wait a maximum of 110 seconds for a
            // response. When that time expires, trigger a timeout command and
            // make the client reconnect.
            GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);

            // Wait a maximum of 30 seconds after a transport connection is lost
            // before raising the Disconnected event to terminate the SignalR connection.
            GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30);

            // For transports other than long polling, send a keepalive packet every
            // 10 seconds. 
            // This value must be no more than 1/3 of the DisconnectTimeout value.
            GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10);

            GlobalHost.Configuration.DefaultMessageBufferSize = 200;

            var hubConfiguration = new HubConfiguration();
            hubConfiguration.EnableCrossDomain = true;
            //In production set nableDetailedErrors = false
            hubConfiguration.EnableDetailedErrors = false;
            hubConfiguration.EnableJavaScriptProxies = true;

            RouteTable.Routes.MapHubs(hubConfiguration);
        }
    }
}